home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / comms / non-internet / samba / source / nameserv.h < prev    next >
C/C++ Source or Header  |  1996-06-26  |  5KB  |  185 lines

  1. /* 
  2.    Unix SMB/Netbios implementation.
  3.    Version 1.9.
  4.    NBT netbios header - version 2
  5.    Copyright (C) Andrew Tridgell 1994-1995
  6.    
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2 of the License, or
  10.    (at your option) any later version.
  11.    
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.    
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20.    
  21. */
  22.  
  23. #define MAX_DGRAM_SIZE 576
  24. #define MIN_DGRAM_SIZE 12
  25.  
  26. #define NMB_PORT 137
  27. #define DGRAM_PORT 138
  28. #define SMB_PORT 139
  29.  
  30. enum name_source {LMHOSTS, REGISTER, SELF, DNS, DNSFAIL};
  31. enum node_type {B_NODE=0, P_NODE=1, M_NODE=2, NBDD_NODE=3};
  32. enum packet_type {NMB_PACKET, DGRAM_PACKET};
  33.  
  34. /* a netbios name structure */
  35. struct nmb_name {
  36.   char name[17];
  37.   char scope[64];
  38.   int name_type;
  39. };
  40.  
  41. /* this is the structure used for the local netbios name list */
  42. struct name_record
  43. {
  44.   struct name_record *next;
  45.   struct name_record *prev;
  46.   struct nmb_name name;
  47.   time_t death_time;
  48.   struct in_addr ip;
  49.   BOOL unique;
  50.   enum name_source source;
  51. };
  52.  
  53. /* this is used by the list of domains */
  54. struct domain_record
  55. {
  56.   struct domain_record *next;
  57.   struct domain_record *prev;
  58.   fstring name;
  59.   time_t lastannounce_time;
  60.   int announce_interval;
  61.   struct in_addr bcast_ip;
  62. };
  63.  
  64. /* this is used to hold the list of servers in my domain */
  65. struct server_record
  66. {
  67.   struct server_record *next;
  68.   struct server_record *prev;
  69.   fstring name;
  70.   fstring comment;
  71.   uint32 servertype;
  72.   time_t death_time;  
  73. };
  74.  
  75. /* a resource record */
  76. struct res_rec {
  77.   struct nmb_name rr_name;
  78.   int rr_type;
  79.   int rr_class;
  80.   int ttl;
  81.   int rdlength;
  82.   char rdata[MAX_DGRAM_SIZE];
  83. };
  84.  
  85. /* define a nmb packet. */
  86. struct nmb_packet
  87. {
  88.   struct {
  89.     int name_trn_id;
  90.     int opcode;
  91.     BOOL response;
  92.     struct {
  93.       BOOL bcast;
  94.       BOOL recursion_available;
  95.       BOOL recursion_desired;
  96.       BOOL trunc;
  97.       BOOL authoritative;
  98.     } nm_flags;
  99.     int rcode;
  100.     int qdcount;
  101.     int ancount;
  102.     int nscount;
  103.     int arcount;
  104.   } header;
  105.  
  106.   struct {
  107.     struct nmb_name question_name;
  108.     int question_type;
  109.     int question_class;
  110.   } question;
  111.  
  112.   struct res_rec *answers;
  113.   struct res_rec *nsrecs;
  114.   struct res_rec *additional;
  115. };
  116.  
  117.  
  118. /* a datagram - this normally contains SMB data in the data[] array */
  119. struct dgram_packet {
  120.   struct {
  121.     int msg_type;
  122.     struct {
  123.       enum node_type node_type;
  124.       BOOL first;
  125.       BOOL more;
  126.     } flags;
  127.     int dgm_id;
  128.     struct in_addr source_ip;
  129.     int source_port;
  130.     int dgm_length;
  131.     int packet_offset;
  132.   } header;
  133.   struct nmb_name source_name;
  134.   struct nmb_name dest_name;
  135.   int datasize;
  136.   char data[MAX_DGRAM_SIZE];
  137. };
  138.  
  139. /* define a structure used to queue packets. this will be a linked
  140.  list of nmb packets */
  141. struct packet_struct
  142. {
  143.   struct packet_struct *next;
  144.   struct packet_struct *prev;
  145.   struct in_addr ip;
  146.   int port;
  147.   int fd;
  148.   time_t timestamp;
  149.   enum packet_type packet_type;
  150.   union {
  151.     struct nmb_packet nmb;
  152.     struct dgram_packet dgram;
  153.   } packet;
  154. };
  155.  
  156.  
  157. /* this defines a list of network interfaces */
  158. struct net_interface {
  159.   struct net_interface *next;
  160.   struct in_addr ip;
  161.   struct in_addr bcast;
  162.   struct in_addr netmask;
  163. };
  164.  
  165.  
  166. /* prototypes */
  167. void free_nmb_packet(struct nmb_packet *nmb);
  168. void free_packet(struct packet_struct *packet);
  169. struct packet_struct *read_packet(int fd,enum packet_type packet_type);
  170. BOOL send_packet(struct packet_struct *p);
  171. struct packet_struct *receive_packet(int fd,enum packet_type type,int timeout);
  172. void make_nmb_name(struct nmb_name *n,char *name,int type,char *this_scope);
  173. BOOL name_query(int fd,char *name,int name_type,
  174.                BOOL bcast,BOOL recurse,
  175.                struct in_addr to_ip, struct in_addr *ip,void (*fn)());
  176. BOOL name_status(int fd,char *name,int name_type,BOOL recurse,
  177.          struct in_addr to_ip,char *master,char *rname,
  178.          void (*fn)());
  179. BOOL send_mailslot_reply(char *mailslot,int fd,char *buf,int len,
  180.              char *srcname,char *dstname,
  181.              int src_type,int dest_type,
  182.              struct in_addr dest_ip,
  183.              struct in_addr src_ip);
  184. char *namestr(struct nmb_name *n);
  185.